/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;

namespace DaveSexton.DocProject
{
	[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes")]	// support for localization
	[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Flags")]
	[AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = true)]
	public class BooleanValuesAttribute : Attribute
	{
		#region Public Properties
		public string TrueValue
		{
			get
			{
				return trueValue;
			}
		}

		public string FalseValue
		{
			get
			{
				return falseValue;
			}
		}
		#endregion

		#region Private / Protected
		private readonly string trueValue, falseValue;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="BooleanValuesAttribute" /> class.
		/// </summary>
		public BooleanValuesAttribute(string trueValue, string falseValue)
		{
			this.trueValue = trueValue;
			this.falseValue = falseValue;
		}
		#endregion

		#region Methods
		public override bool IsDefaultAttribute()
		{
			return trueValue == null && falseValue == null;
		}

		public override bool Match(object obj)
		{
			BooleanValuesAttribute attribute = obj as BooleanValuesAttribute;

			return attribute != null
				&& string.Equals(attribute.trueValue, trueValue, StringComparison.OrdinalIgnoreCase)
				&& string.Equals(attribute.falseValue, falseValue, StringComparison.OrdinalIgnoreCase);
		}
		#endregion
	}
}
